import { ref } from 'vue'
import { defineStore } from 'pinia'
import { loginStatus } from '@/apis/login.js'
import { useCookieStore } from './cookieStore'

export const useUserInfoStore = defineStore('user', () => {
  const userInfo = ref({})
  const useCookie = useCookieStore()
  const getLoginStatus = async () => {
    if (useCookie.cookie.cookie) {
      const { data } = await loginStatus(useCookie.cookie.cookie)
      userInfo.value = data.data
    }
  }

  // 清空用户信息
  const clearUesrInfo = () => {
    userInfo.value.userInfo = {}
  }
  
  return {
    userInfo,
    getLoginStatus,
    clearUesrInfo
  }
}, {
  persist: true
})
